package com.enjoyor.soa.traffic.core.tpcms.mapper.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.core.tpcms.constant.InfoLimitPeriodSqlId;
import com.enjoyor.soa.traffic.core.tpcms.domain.InfoLimitPeriod;
import com.enjoyor.soa.traffic.core.tpcms.mapper.IInfoLimitPeriodMapper;
import com.enjoyor.soa.traffic.frame.support.mybatis.mapper.impl.BaseMapper;
import com.enjoyor.soa.traffic.util.helper.TimeHelper;

@Service
@Transactional
public class InfoLimitPeriodMapper extends BaseMapper<InfoLimitPeriod> implements IInfoLimitPeriodMapper {

    @Override
    public void insert(InfoLimitPeriod infoLimitPeriod) {
        infoLimitPeriod.setPeriodId(String.valueOf(System.nanoTime()));
        infoLimitPeriod.setRecordTime(TimeHelper.dateToLongString());
        super.insert(infoLimitPeriod);
    }

    @Override
    public int deleteLimitPeriod(String applyZoneId) {
        return sqlSessionTemplate.delete(getSqlName(InfoLimitPeriodSqlId.SQL_DELETE_ALL), applyZoneId);
    }

    @Override
    public void insertLimitPeriod(List<InfoLimitPeriod> LimitPeriods) {
        if ((LimitPeriods == null) || (LimitPeriods.isEmpty())) {
            return;
        }
        for (InfoLimitPeriod infoLimitPreiod : LimitPeriods) {
            infoLimitPreiod.setRecordTime(TimeHelper.dateToLongString());
            sqlSessionTemplate.insert(getSqlName(InfoLimitPeriodSqlId.SQL_INSERT), infoLimitPreiod);
        }
    }

    @Override
    public List<InfoLimitPeriod> getLimitPeriodList(String applyZoneId) {
        return sqlSessionTemplate.selectList(InfoLimitPeriodSqlId.SQL_SELECT_ALL, applyZoneId);
    }

}
